﻿using BCDto.Common.ErrorMessage;
using BCDto.Location.Driver;
using BCDto.Location.Horseman;
using BCService.TMS.Location.Driver;
using BCService.TMS.Location.Horseman;
using BCTMSRESTful.Configs;
using Microsoft.AspNetCore.Mvc;

namespace BCTMSRESTful.Controllers.DriverApp.Location
{
    /// <summary>
    /// 位置信息
    /// </summary>
    [ApiExplorerSettings(GroupName = "DriverApp")]
    [Route("api/v1/DriverApp/[controller]")]
    public class LocationController : DriverAppBaseController
    {
        private readonly IDriverLocationService driverLocationService;
        private readonly IHorsemanLocationService horsemanLocationService;

        public LocationController(IDriverLocationService driverLocationService,IHorsemanLocationService horsemanLocationService)
        {
            this.driverLocationService = driverLocationService;
            this.horsemanLocationService = horsemanLocationService;
        }

        /// <summary>
        /// 司机上传位置信息
        /// </summary>
        /// <returns></returns>
        /// <response code="200">司机位置信息。</response>
        /// <response code="204">无法找到指定的用户。</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="401">请求需要认证或者认证信息已过期。</response>
        /// <response code="500">服务器内部错误。</response>
        [HttpPost("[action]")]
        [Log("司机上传位置信息")]
        [ProducesResponseType(typeof(DriverLocationBsonDto), 200)]
        [ProducesResponseType(typeof(ErrorMessageDto), 400)]
        [ProducesResponseType(typeof(ErrorMessageDto), 500)]
        public IActionResult DriverUpload([FromBody] DriverLocationRequestDto dto)
        {
            if (this.Driver == null)
            {
                return this.Ok();
            }
            return Ok(driverLocationService.SetLocation(this.Driver, dto));
        }


        /// <summary>
        /// 骑手上传位置信息
        /// </summary>
        /// <returns></returns>
        /// <response code="200">骑手位置信息。</response>
        /// <response code="204">无法找到指定的用户。</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="401">请求需要认证或者认证信息已过期。</response>
        /// <response code="500">服务器内部错误。</response>
        [HttpPost("[action]")]
        [Log("骑手上传位置信息")]
        [ProducesResponseType(typeof(HorsemanLocationBsonDto), 200)]
        [ProducesResponseType(typeof(ErrorMessageDto), 400)]
        [ProducesResponseType(typeof(ErrorMessageDto), 500)]
        public IActionResult HorsemanUpload([FromBody] HorsemanLocationRequestDto dto)
        {
            if (this.Driver == null)
            {
                return this.Ok();
            }
            return Ok(horsemanLocationService.SetLocation(this.Driver, dto));
        }
    }
}
